<?php

namespace app\index\controller;

class Basic extends \think\Controller
{
    public function is_login()
    {
        $redis_config =  config('cache.default');
        $member_id = session('member_id');
        $redis = new \think\cache\driver\Redis($redis_config);
        $ip = $redis->get('member_' . $member_id);
        //有session且登陆的ip地址相同
//        if (!empty($member_id)&&$ip == $this->request->server('remote_addr'))
        if (!empty($member_id))
        {
            return true;
        }
        return FALSE;
    }

    protected function initialize()
    {
        $except_arr = ['login', 'register','captcha','index','example'];
        parent::initialize();
        $this->assign('STATIC_PATH',"https://{$_SERVER['HTTP_HOST']}/static/");
        if (!$this->is_login() && !in_array($this->request->action(), $except_arr))
        {
            return $this->redirect('member/login');
        }
    }

}
